﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;
using System.Data.SqlClient;
using WFNetLib.ADO;

namespace DAL
{
    public class ModuleDal
    {
        /// <summary>
        /// 获取前台左侧菜单大类
        /// </summary>
        /// <returns></returns>
        public List<ModuleData> GetModuleGroup_UI()
        {
            SqlDataReader res = null;
            List<ModuleData> ListModel = new List<ModuleData>();
            StringBuilder strSQL = new StringBuilder();
            strSQL.Append("SELECT module_id,");
            strSQL.Append("module_name,");
            strSQL.Append("module_descr,");
            strSQL.Append("parent_id,");
            strSQL.Append("module_url,");
            strSQL.Append("is_manage_module,");
            strSQL.Append("create_user_id,");
            strSQL.Append("create_timestamp,");
            strSQL.Append("update_user_id,");
            strSQL.Append("update_timestamp ");
            strSQL.Append(" FROM  module ");
            strSQL.Append(" where is_manage_module = 0 and ");
            strSQL.Append(" parent_id = 0 and ");
            strSQL.Append(" active_flag = 'true'");
            res = SQLServerOP.ReaderExecuteSQL(strSQL.ToString());
            if (res != null)
            {
                while (res.Read())
                {
                    ModuleData model = ModuleDataFactory.Construct(res);
                    ListModel.Add(model);
                }
            }
            res.Close();
            res.Dispose();
            return ListModel;
        }
        /// <summary>
        /// 根据分类ID获取子类菜单
        /// </summary>
        /// <param name="ModelID"></param>
        /// <returns></returns>
        public List<ModuleData> GetModuleDetail_UI(string ModelID)
        {
            SqlDataReader res = null;
            List<ModuleData> ListModel = new List<ModuleData>();
            StringBuilder strSQL = new StringBuilder();
            strSQL.Append("SELECT module_id,");
            strSQL.Append("module_name,");
            strSQL.Append("module_descr,");
            strSQL.Append("parent_id,");
            strSQL.Append("module_url,");
            strSQL.Append("is_manage_module,");
            strSQL.Append("create_user_id,");
            strSQL.Append("create_timestamp,");
            strSQL.Append("update_user_id,");
            strSQL.Append("update_timestamp ");
            strSQL.Append(" FROM  module ");
            strSQL.Append(" where is_manage_module = 0 and ");
            strSQL.Append(" parent_id = " + ModelID + " and ");
            strSQL.Append(" active_flag = 'true'");
            res = SQLServerOP.ReaderExecuteSQL(strSQL.ToString());
            if (res != null)
            {
                while (res.Read())
                {
                    ModuleData model = ModuleDataFactory.Construct(res);
                    ListModel.Add(model);
                }
            }
            res.Close();
            res.Dispose();
            return ListModel;
        }
    }
}
